package com.lframework.xingyun.basedata.bo.product.assistance;

import com.lframework.starter.web.core.bo.BaseBo;
import com.lframework.starter.web.core.utils.ApplicationUtil;
import com.lframework.xingyun.basedata.bo.product.info.ProductInfoBo;
import com.lframework.xingyun.basedata.entity.ProductAssistance;
import com.lframework.xingyun.basedata.service.product.ProductService;
import io.swagger.annotations.ApiModelProperty;

import lombok.Data;

import java.util.Objects;


/**
 * <p>
 * 商品辅料表 GetBo
 * </p>
 *
 */
@Data
public class GetProductAssistanceBo extends BaseBo<ProductAssistance> {

    /**
     * ID
     */
    @ApiModelProperty("ID")
    private String id;

    /**
     * 主商品id
     */
    @ApiModelProperty("主商品id")
    private String productMainId;

    /**
     * 辅料商品id
     */
    @ApiModelProperty("辅料商品id")
    private String productId;

    /**
     * 显示顺序
     */
    @ApiModelProperty("显示顺序")
    private Integer displayNum;

    /**
     * 商品类型
     */
    @ApiModelProperty("商品类型")
    private Integer productType;

    /**
     * 商品编码
     */
    @ApiModelProperty("商品编码")
    private String productCode;

    /**
     * 商品名称
     */
    @ApiModelProperty("商品名称")
    private String productName;

    /**
     * SKU编码
     */
    @ApiModelProperty("SKU编码")
    private String skuCode;

    /**
     * 商品简码
     */
    @ApiModelProperty("商品简码")
    private String externalCode;

    /**
     * 单位
     */
    @ApiModelProperty("单位")
    private String unit;

    /**
     * 规格
     */
    @ApiModelProperty("规格")
    private String spec;

    /**
     * 参考销售价（元）
     */
    @ApiModelProperty("参考销售价（元）")
    private String salePrice;

    /**
     * 商品分类id
     */
    @ApiModelProperty("商品分类id")
    private String productCategoryId;

    /**
     * 商品分类名称
     */
    @ApiModelProperty("商品分类名称")
    private String categoryName;

    /**
     * 商品品牌
     */
    @ApiModelProperty("商品品牌Id")
    private String productBrandId;

    /**
     * 商品品牌名称
     */
    @ApiModelProperty("商品品牌名称")
    private String brandName;

    public GetProductAssistanceBo() {

    }

    public GetProductAssistanceBo(ProductAssistance dto) {

        super(dto);
    }

    @Override
    public BaseBo<ProductAssistance> convert(ProductAssistance dto) {
        return super.convert(dto);
    }

    @Override
    protected void afterInit(ProductAssistance dto) {
        ProductService productService = ApplicationUtil.getBean(ProductService.class);
        ProductInfoBo productInfoBo = productService.selectByBo(this.productId);
        if (Objects.nonNull(productInfoBo)) {
            this.productType = productInfoBo.getProductType();
            this.productCode = productInfoBo.getProductCode();
            this.productName = productInfoBo.getProductName();
            this.skuCode = productInfoBo.getSkuCode();
            this.externalCode = productInfoBo.getExternalCode();
            this.unit = productInfoBo.getUnit();
            this.spec = productInfoBo.getSpec();
            this.salePrice = productInfoBo.getSalePrice();
            this.productCategoryId = productInfoBo.getProductCategoryId();
            this.categoryName = productInfoBo.getCategoryName();
            this.productBrandId = productInfoBo.getProductBrandId();
            this.brandName = productInfoBo.getBrandName();
        }
    }
}

